from django.db import models

class Movie(models.Model):
    title = models.CharField(max_length=200, primary_key=True)
    year = models.PositiveSmallIntegerField()
    searchPair = models.ManyToManyField('self', symmetrical=False, blank=True, through='SearchResult')
    searchSingle = models.BigIntegerField()
    link = models.CharField(max_length=256)
    def __unicode__(self):
        return '%s (%s)' % (self.title, self.year)

class SearchResult(models.Model):
    movie1 = models.ForeignKey(Movie, related_name='searchresult_set1')
    movie2 = models.ForeignKey(Movie, related_name='searchresult_set2')
    numResults = models.BigIntegerField()
    def __unicode__(self):
        name1 = getattr(self.movie1, 'title')
        name2 = getattr(self.movie2, 'title')
        # can also use: getattr(self, 'movie1').__unicode__()
        return '"%s" & "%s"' % (name1, name2)

